#include "audiomanager.h"
#include "qterminal.h"

bool AudioManager::play(const QString audioFile, int cardId, int deviceId, QString *message)
{
    bool ret = true;
    QTerminal terminal;
    ret = ret && terminal.run(QString("aplay -D plughw:%1,%2 %3").arg(cardId).arg(deviceId).arg(audioFile), message);
    return ret;
}

bool AudioManager::stop(QString *message)
{
    bool ret = true;
    QTerminal terminal;
    ret = ret && terminal.run("killall aplay", message);
    return ret;
}

bool AudioManager::setVolume(int value, int m_cardId, QString *message)
{
    bool ret = true;
    QTerminal terminal;
    int volume = qMin(qMax(0, value), 100);
    ret = ret && terminal.run(QString("pactl set-sink-volume %1 %2%").arg(m_cardId).arg(volume), message);
    return ret;
}
